package scsc.pm;

import scsc.pub.tools.Logger;
import scsc.pub.db.DBManage;
import scsc.web.system.data.TransPageData;
import scsc.pub.data.Transpage;
import scsc.pub.exception.UnifyUserException;
import scsc.pub.db.PageListData;
import java.util.ArrayList;
import java.util.List;
import scsc.pub.tools.StringUtil;

public class SysTranspage {
  private Logger logger = Logger.getLogger(SysTranspage.class);

  public void createTranspage(
      DBManage dbmanage,
      TransPageData transpageData) throws UnifyUserException {
    Transpage data = new Transpage();
    data.setTranscode(transpageData.getTranscode());
    data.setPageurl(transpageData.getPageurl());
    dbmanage.sqlSave(data);
  }

  public void deleteTranspage(DBManage dbmanage, String pageUrl) throws
      UnifyUserException {
    pageUrl = StringUtil.trim(pageUrl);
    String sqlStr = "delete from scsc.pub.data.Transpage where pageurl='" + pageUrl +
        "'";
    dbmanage.sqlDelete(sqlStr);
  }

  public void modifyTranspage(
      DBManage dbmanage,
      TransPageData transpageData) throws UnifyUserException {
    Transpage data = new Transpage();
    data.setTranscode(transpageData.getTranscode());
    data.setPageurl(transpageData.getPageurl());
    dbmanage.sqlUpdate(data);
  }

  public void selectTranspages(DBManage dbmanage, PageListData footer) {
    String sqlStr = "select new scsc.web.system.data.TransPageData(transpage.transcode,transpage.pageurl) from scsc.pub.data.Transpage as transpage order by transpage.transcode";
    dbmanage.sqlQueryPage(sqlStr, footer);
  }

  public java.util.ArrayList selectTranspages(DBManage dbmanage,
                                              String transactCode,
                                              String pageUrl) {
    String sqlStr = "select new scsc.web.system.data.TransPageData(transpage.transcode,transpage.pageurl) from scsc.pub.data.Transpage as transpage where 1=1";
    if (transactCode.length() > 0) {
      sqlStr = sqlStr + " and transpage.transcode like '%" + transactCode +
          "%'";
    }
    if (pageUrl.length() > 0) {
      sqlStr = sqlStr + " and transpage.pageurl = '" + pageUrl +
          "'";
    }
    List result = dbmanage.sqlQuery(sqlStr);
    return (ArrayList) result;
  }
}
